package com.tw.trips.domain;

import java.util.Date;
import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;

@NodeEntity
public class Comment {

	@GraphId
	private Long nodeiD;

	private Date createdOn;

	@Fetch
	@RelatedTo(type = "COMMENTED", elementClass = Update.class)
	private Update update;

	@Fetch
	private Traveller commentedBy;

	private String message;

	@RelatedTo(type = "ITHELPS_COMMENT", elementClass = ItHelps.class, direction = Direction.INCOMING)
	@Fetch
	private Set<ItHelps> itHelps;

	public Comment comment(Date createdOn, String message) {
		if (createdOn != null)
			this.createdOn = createdOn;
		if (message != null && !message.isEmpty())
			this.message = message;
		return this;
	}

	public Comment(Date createdOn, Traveller commentedBy, String message) {
		this.createdOn = createdOn;
		this.commentedBy = commentedBy;
		this.message = message;
	}

	public Comment() {
		super();
	}

	/**
	 * @return the nodeiD
	 */
	public Long getNodeiD() {
		return nodeiD;
	}

	/**
	 * @param nodeiD
	 *            the nodeiD to set
	 */
	public void setNodeiD(Long nodeiD) {
		this.nodeiD = nodeiD;
	}

	/**
	 * @return the createdOn
	 */
	public Date getCreatedOn() {
		return createdOn;
	}

	/**
	 * @param createdOn
	 *            the createdOn to set
	 */
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	/**
	 * @return the commentedBy
	 */
	public Traveller getCommentedBy() {
		return commentedBy;
	}

	/**
	 * @param commentedBy
	 *            the commentedBy to set
	 */
	public void setCommentedBy(Traveller commentedBy) {
		this.commentedBy = commentedBy;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message
	 *            the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the itHelps
	 */
	public Set<ItHelps> getItHelps() {
		return itHelps;
	}

	/**
	 * @param itHelps
	 *            the itHelps to set
	 */
	public void setItHelps(Set<ItHelps> itHelps) {
		this.itHelps = itHelps;
	}

	/**
	 * @return the update
	 */
	public Update getUpdate() {
		return update;
	}

	/**
	 * @param update
	 *            the update to set
	 */
	public void setUpdate(Update update) {
		this.update = update;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Comment [nodeiD=" + nodeiD + ", createdOn=" + createdOn
				+ ", update=" + update + ", commentedBy=" + commentedBy
				+ ", message=" + message + ", itHelps size ="
				+ (itHelps != null ? itHelps.size() : 0) + "]";
	}

}
